/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Gui;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

/**
 *
 * @author SONY
 */
class ImagePanel extends JPanel {

    private Image img;

    /**
     Creates an ImageIcon from the specified file. The image will
     * be preloaded by using MediaTracker to monitor the loading state
     * of the image. The specified String can be a file name or a
     * file path. When specifying a path, use the Internet-standard
     * forward-slash ("/") as a separator.
     *
     * @param img is a String specifying a filename or path
     * @see #setImage(Image)
     */
    
    public ImagePanel(String img, int width, int high) {
        this(new ImageIcon(img).getImage(), width, high);
        
    }
    public ImagePanel(String img) {
        this(new ImageIcon(img).getImage());
    }

    public ImagePanel(Image img) {
        this.img = img;
    }

    public ImagePanel(Image img, int width, int high){
        this.img = img.getScaledInstance(width, high, Image.SCALE_DEFAULT);
    }

    /**
     * Set new image for Panel
     *
     * @param image 
     * @see #setImage(Image)
     */
    public void setImage(Image image){
        this.img = image;
        repaint();
    }

    /**
     * Creates an ImageIcon from the specified file. The image will
     * be preloaded by using MediaTracker to monitor the loading state
     * of the image. The specified String can be a file name or a
     * file path. When specifying a path, use the Internet-standard
     * forward-slash ("/") as a separator.
     * (The string is converted to an URL, so the forward-slash works
     * on all systems.)
     * For example, specify:
     * <pre>
     *    new ImageIcon("images/myImage.gif") </pre>
     *
     * @param path a String specifying a filename or path
     * @see #setImage(Image)
     */
    public void setImage(String path){
        this.setImage(new ImageIcon(path).getImage());
    }

    @Override
    public void paintComponent(Graphics g) {
        ((Graphics2D) g).drawImage(img, 0, 0, this);
    }
}
